package com.example.csmall.product.controller;

import com.example.csmall.product.mapper.AttributeTemplateMapper;
import com.example.csmall.product.pojo.dto.AttributeTemplateAddNewDTO;
import com.example.csmall.product.pojo.dto.AttributeTemplateUpdateDTO;
import com.example.csmall.product.pojo.vo.AttributeTemplateListItemVO;
import com.example.csmall.product.pojo.vo.AttributeTemplateStandardVO;
import com.example.csmall.product.service.AttributeTemplateService;
import com.example.csmall.product.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Validated
@Api(tags = "02 属性模板")
@RequestMapping("/attributeTemplates")
public class AttributeTemplateController {

    @Autowired
    AttributeTemplateService service;

    @ApiOperation("添加属性模板")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid AttributeTemplateAddNewDTO attributeTemplateAddNewDTO){
        service.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除记录")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        service.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据id修改记录")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateInfoById(@PathVariable Long id, AttributeTemplateUpdateDTO attributeTemplateUpdateDTO){
        service.updateInfoById(id,attributeTemplateUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("属性模板列表")
    @GetMapping("")
    public JsonResult<List<AttributeTemplateListItemVO>> list(){
        List<AttributeTemplateListItemVO> list = service.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据id查询属性模板")
    @GetMapping("/{id}")
    public JsonResult<AttributeTemplateStandardVO> getStandardById(@PathVariable Long id){
        AttributeTemplateStandardVO list = service.getStandardById(id);
        return JsonResult.ok(list);
    }

}
